﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:Elysium.Markup"
                    xmlns:params="clr-namespace:Elysium.Parameters"
                    xmlns:controls="clr-namespace:Elysium.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Themes/SharedResources.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Themes/Ranges/ProgressBar.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Themes/Buttons/Button.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Themes/Windows/Window.Buttons.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Themes/Icons.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="{x:Type controls:Window}" TargetType="{x:Type controls:Window}">
        <Setter Property="Background" Value="{markup:ThemeResource BackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{markup:ThemeResource AccentBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="{markup:ThemeResource ForegroundBrush}"/>
        <Setter Property="FontFamily" Value="Segoe UI"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.TextFontSize), Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="Medium"/>
        <Setter Property="FontStyle" Value="Normal"/>
        <Setter Property="FontWeight" Value="Normal"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType"/>
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>
        <Setter Property="HasDropShadow" Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="ResizeMode" Value="CanResizeWithGrip"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:Window}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            UseLayoutRounding="True"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid x:Name="PART_LayoutRoot">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid x:Name="PART_Caption"
                                  Grid.Row="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Image x:Name="PART_Icon"
                                       Grid.Column="0"
                                       Grid.Row="0" Grid.RowSpan="2"
                                       Source="{TemplateBinding Icon}"/>
                                <TextBlock x:Name="PART_Title"
                                           Grid.Column="1"
                                           Grid.Row="0" Grid.RowSpan="2"
                                           Text="{TemplateBinding Title}"
                                           FontSize="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:General.TitleFontSize), Mode=OneWay}"
                                           FontWeight="Normal"
                                           TextTrimming="CharacterEllipsis"
                                           Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:General.BoldPadding), Mode=OneWay}"
                                           VerticalAlignment="Center"/>
                                <Decorator Grid.Column="2"
                                           Grid.Row="0" Grid.RowSpan="2"
                                           controls:Window.IsTitleBarHost="True"
                                           WindowChrome.IsHitTestVisibleInChrome="True"/>
                                <Grid Grid.Column="3"
                                      Grid.Row="0" Grid.RowSpan="2"
                                      WindowChrome.IsHitTestVisibleInChrome="True">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Button x:Name="PART_Minimize"
                                            Grid.Column="0"
                                            BorderThickness="0"
                                            Command="{x:Static controls:WindowCommands.Minimize}"
                                            ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:Window.MinimizeButtonToolTip), Mode=OneWay}"
                                            Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=DefaultCaptionButtonStyle}}">
                                        <Path Data="{StaticResource MinimizeIcon}"
                                              Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=Foreground, Mode=OneWay}"
                                              Stretch="None"
                                              Width="10" Height="10"/>
                                    </Button>
                                    <Button x:Name="PART_Maximize"
                                            Grid.Column="1"
                                            BorderThickness="0"
                                            Command="{x:Static controls:WindowCommands.Maximize}"
                                            ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:Window.MaximizeButtonToolTip), Mode=OneWay}"
                                            Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=DefaultCaptionButtonStyle}}">
                                        <Path Data="{StaticResource MaximizeIcon}"
                                              Stroke="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=Foreground, Mode=OneWay}"
                                              Stretch="None"
                                              Width="10" Height="10"/>
                                    </Button>
                                    <Button x:Name="PART_Restore"
                                            Grid.Column="1"
                                            BorderThickness="0"
                                            Command="{x:Static controls:WindowCommands.Restore}"
                                            ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:Window.RestoreButtonToolTip), Mode=OneWay}"
                                            Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=DefaultCaptionButtonStyle}}"
                                            Visibility="Hidden">
                                        <Path Data="{StaticResource RestoreIcon}"
                                              Stroke="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=Foreground, Mode=OneWay}"
                                              Stretch="None"
                                              Width="10" Height="10"/>
                                    </Button>
                                    <Button x:Name="PART_Close"
                                            Grid.Column="2"
                                            BorderThickness="0"
                                            Command="{x:Static controls:WindowCommands.Close}"
                                            ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:Window.CloseButtonToolTip), Mode=OneWay}"
                                            Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=DefaultCaptionButtonStyle}}">
                                        <Path Data="{StaticResource CloseIcon}"
                                              Stroke="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=Foreground, Mode=OneWay}"
                                              Stretch="None"
                                              Width="10" Height="10"/>
                                    </Button>
                                </Grid>
                                <controls:ProgressBar x:Name="PART_ProgressBar"
                                                      Grid.Column="0" Grid.ColumnSpan="4"
                                                      Grid.Row="0"
                                                      Background="{DynamicResource TransparentBrush}"
                                                      Value="{TemplateBinding Progress}"
                                                      VerticalAlignment="Top"
                                                      Height="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldThicknessValue), Mode=OneWay}"/>
                            </Grid>
                            <AdornerDecorator Grid.Row="1"
                                              TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                                              TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                                              RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}">
                                <ContentPresenter Margin="{TemplateBinding Padding}"/>
                            </AdornerDecorator>
                            <Decorator Grid.Row="1"
                                       controls:Window.IsApplicationBarHost="True"/>
                            <ResizeGrip x:Name="PART_Grip"
                                        Grid.Row="1"
                                        WindowChrome.ResizeGripDirection="BottomRight"
                                        IsTabStop="False"
                                        Visibility="Collapsed"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Bottom"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.TitleFontSize), Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                            <Setter TargetName="PART_Title" Property="TextOptions.TextFormattingMode" Value="Ideal"/>
                        </DataTrigger>
                        <Trigger Property="IsBusy" Value="True">
                            <Setter TargetName="PART_ProgressBar" Property="State" Value="Indeterminate"/>
                        </Trigger>
                        <Trigger Property="controls:Window.IsMainWindow" Value="True">
                            <Setter TargetName="PART_Caption" Property="Background" Value="{DynamicResource AccentBrush}"/>
                            <Setter TargetName="PART_ProgressBar" Property="Foreground" Value="{DynamicResource ContrastBrush}"/>
                            <Setter TargetName="PART_Title" Property="Foreground" Value="{DynamicResource ContrastBrush}"/>
                            <Setter TargetName="PART_Minimize" Property="Style" Value="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=MainWindowCaptionButtonStyle}}"/>
                            <Setter TargetName="PART_Maximize" Property="Style" Value="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=MainWindowCaptionButtonStyle}}"/>
                            <Setter TargetName="PART_Restore" Property="Style" Value="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=MainWindowCaptionButtonStyle}}"/>
                            <Setter TargetName="PART_Close" Property="Style" Value="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type controls:Window}, ResourceId=MainWindowCaptionButtonStyle}}"/>
                        </Trigger>
                        <Trigger Property="WindowState" Value="Maximized">
                            <Setter TargetName="PART_Maximize" Property="Visibility" Value="Hidden"/>
                            <Setter TargetName="PART_Restore" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="WindowStyle" Value="None">
                            <Trigger.Setters>
                                <Setter TargetName="PART_Title" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Minimize" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Maximize" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Restore" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Close" Property="Visibility" Value="Collapsed"/>
                            </Trigger.Setters>
                        </Trigger>
                        <Trigger Property="WindowStyle" Value="ToolWindow">
                            <Trigger.Setters>
                                <Setter TargetName="PART_Minimize" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Maximize" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Restore" Property="Visibility" Value="Collapsed"/>
                            </Trigger.Setters>
                        </Trigger>
                        <Trigger Property="ResizeMode" Value="NoResize">
                            <Trigger.Setters>
                                <Setter TargetName="PART_Minimize" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Maximize" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Restore" Property="Visibility" Value="Collapsed"/>
                            </Trigger.Setters>
                        </Trigger>
                        <Trigger Property="ResizeMode" Value="CanMinimize">
                            <Trigger.Setters>
                                <Setter TargetName="PART_Maximize" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="PART_Restore" Property="Visibility" Value="Collapsed"/>
                            </Trigger.Setters>
                        </Trigger>
                        <Trigger Property="ResizeMode" Value="CanResizeWithGrip">
                            <Trigger.Setters>
                                <Setter TargetName="PART_Grip" Property="Visibility" Value="Visible"/>
                            </Trigger.Setters>
                        </Trigger>
                    </ControlTemplate.Triggers>                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>        
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <Trigger Property="HasDropShadow" Value="False">
                <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.DefaultThickness), Mode=OneWay}"/>
            </Trigger>
            <Trigger Property="WindowStyle" Value="{x:Static WindowStyle.None}">
                <Setter Property="ResizeMode" Value="NoResize"/>
            </Trigger>
            <Trigger Property="WindowStyle" Value="{x:Static WindowStyle.ToolWindow}">
                <Setter Property="ResizeMode" Value="NoResize"/>
            </Trigger>            
        </Style.Triggers>        
    </Style>
    
</ResourceDictionary>